unit FInterface;

interface
uses
	Windows, FOpenGl, FBase, FTextures, FFonts, SysUtils, FGlWindow, FFPS, FCursor;

procedure DrawInterface();

implementation

procedure DrawImage(path : string; partX, partY, partW, partH, imageW, imageH, NewW, NewH : extended);
begin
	glEnable(GL_TEXTURE_2D);
	BindTexture(path);
	glBegin(GL_QUAD_STRIP);
		glTexCoord2f(partX / imageW, partY / imageH);
		glVertex3f(0, 0, 0.5);

		glTexCoord2f((partX + partW) / imageW, partY / imageH);
		glVertex3f(NewW, 0, 0.5);

		glTexCoord2f(partX / imageW, (partY + partH) / imageH);
		glVertex3f(0, NewH, 0.5);

		glTexCoord2f((partX + partW) / imageW, (partY + partH) / imageH);
		glVertex3f(NewW, NewH, 0.5);
	glEnd();
	glDisable(GL_TEXTURE_2D);
end;

procedure DrawInterface();
begin
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluOrtho2D( 0, Window.X, Window.Y, 0 );
	glMatrixMode( GL_MODELVIEW );

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glPushMatrix();
	DrawImage('Textures/Interface/Tile1.tga', 0, 0, 512, 128, 512, 512, 512/1600*Window.X, 128/1200*Window.Y);
	glTranslatef(512/1600*Window.X, 0, 0);
	DrawImage('Textures/Interface/Tile2.tga', 0, 0, 512, 128, 512, 512, 512/1600*Window.X, 128/1200*Window.Y);
	glTranslatef(512/1600*Window.X, 0, 0);
	DrawImage('Textures/Interface/Tile3.tga', 0, 0, 512, 128, 512, 512, 512/1600*Window.X, 128/1200*Window.Y);
	glTranslatef(512/1600*Window.X, 0, 0);
	DrawImage('Textures/Interface/Tile4.tga', 0, 0, 64, 128, 64, 512, 64/1600*Window.X, 128/1200*Window.Y);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0, Window.Y - 384/1200*Window.Y, 0);

	DrawImage('Textures/Interface/Tile1.tga', 0, 128, 512, 384, 512, 512, 512/1600*Window.X, 384/1200*Window.Y);
	glTranslatef(512/1600*Window.X, 0, 0);
	DrawImage('Textures/Interface/Tile2.tga', 0, 128, 512, 384, 512, 512, 512/1600*Window.X, 384/1200*Window.Y);
	glTranslatef(512/1600*Window.X, 0, 0);
	DrawImage('Textures/Interface/Tile3.tga', 0, 128, 512, 384, 512, 512, 512/1600*Window.X, 384/1200*Window.Y);
	glTranslatef(512/1600*Window.X, 0, 0);
	DrawImage('Textures/Interface/Tile4.tga', 0, 128, 64, 384, 64, 512, 64/1600*Window.X, 384/1200*Window.Y);
	glPopMatrix();

	glColor3f(1, 1, 1);
	glPushMatrix();
	glTranslatef(Window.X - 60, 10, 1);
	glPrint('500', 22);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(Window.X - 135, 3, 0.1);
	DrawImage('Textures/Interface/Icons/ResourceUndead.tga', 0, 0, 32, 32, 32, 32, 32, 32);
	glTranslatef(50,0,-1);
	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);


	glPushMatrix();
		glColor3f(1, 1, 1);
		glTranslatef(Window.X div 2 - 55, Window.Y - 200, 1);
//		glRasterPos2f(0, Window.Y - 350);
		glPrint(PChar('Goule'), 28);
		glColor3f(1, 1, 1);
	glPopMatrix();

	glPushMatrix();
		glColor3f(1, 0, 1);
		glTranslatef(Window.X div 2 - 55, Window.Y - 260, 1);
//		glRasterPos2f(0, Window.Y - 350);
		glPrint(PChar('FPS : ' + IntToStr(Count.FPS)), 28);
		glColor3f(1, 1, 1);
	glPopMatrix();

	glPushMatrix();
//		glRasterPos2f(0, Window.Y - 400);
		glTranslatef(Window.X div 2 - 300, Window.Y - 260, 1);
		glPrint(PChar('Pos : ' + IntToStr(Mouse.Hover)), 28);
	glPopMatrix();
end;

end.

